﻿using Echo.Context.UltiProNet.Contexts;
using Echo.Core.TestAbstraction.WebUITest.MbUnit;
using MbUnit.Framework;

////*************************************************************************************************************************************
////Created by: Shawn Nicholson (ECHO)
////Date created: 09/30/2013
////Modified by: David Mello (SWAT Conversion)
////Date modified: 07/10/2013
////Reason: Swat Conversion.
////ULTI-42647 - This script tests the basic GUI functionality for Stream-lined Instant when system has records in the PAW2Approvals and PAW2ApprovalDates tables.  
//// When the Final Reconciliation Date is greater than the system date, the page should render with a link on the Not Started status of a pay group that, when selected, 
//// will go to the Payroll Overview page and open a payroll.  Conversely, when the Final Reconciliation Date is less than the system date, there should not be a link, 
//// and the status should be Year End Reconciliation.
////*************************************************************************************************************************************

namespace Echo.Automation.Payroll.W2_Print_Approval
{
    using Echo.Models.UltimateSoftware.WebUITest.MbUnit;

    [TestFixture]
    [Author("David Mello", "david_mello@ultimatesoftware.com")]
    [Category("W2 Print Approval")]
    [Release("10.7.1")]
    [Header("Config")]
    [Config(".NET")]
    public class PayGroupOpenDisabledInSlic : MbUnitAutomatedTest
    {
        UltiPro ultiPro;
        UltiProDatabaseContext database;

        [FixtureSetUp]
        public void FixtureSetUp()
        {
            this.ultiPro = Launch<UltiPro>();
            this.database = Init<UltiProDatabaseContext>();
            this.database.Company = ConfigDatabase("ULTIPRO_SB340");
            this.database.Company.AddRollBack("paw2ApprovalDates");
            this.database.Company.AddRollBack("paw2Approvals");

            this.ultiPro.Pages.Login.LoginAs("GreenT", "Password1", Config.LanguageCode);
        }

        [FixtureTearDown]
        public void FixtureTearDown()
        {
            this.database.Company.RollBackDatabase();
            this.ultiPro.Browser.Quit();
        }

        [TearDown]
        public void TestTearDown()
        {
            this.database.Company.RollBackDatabase();
        }

        [SetUp]
        public void TestSetup()
        {
            this.database.Company.Execute("DELETE FROM paW2ApprovalDates");
            this.database.Company.Execute("DELETE FROM PAW2Approvals");
        }

        /// <summary>
        /// Verify that with no W2 Approval records, there is a link in payroll status for Not Started.
        /// </summary>
        [Test]
        public void VerifyPayrollStatusIsNotStarted()
        {
            // Given there are no records in PAW2ApprovalDates and PAW2Approvals.

            // When I visit Create Instant Checks.
            ultiPro.Macros.Payroll.GoToInstantChecks();
            ultiPro.Pages.WPREmployeePaySummary.WPREmployeePaySummaryGrid.Click(b => b.FilterButton);

            // Then Payroll status is not started with a link.
            this.ultiPro.Pages.WPREmployeePaySummary.WPREmployeePaySummaryGrid.Row(
                c => c.Name, "Appleton, Larry A.", c1 => c1.PayGroup, "WorkPlace Weekly").Is(cell => cell.PayrollStatusLink, "innerHtml", "Not Started");

            this.ultiPro.Pages.WPREmployeePaySummary.WPREmployeePaySummaryGrid.Row(
                c => c.Name, "Appleton, Larry A.", c1 => c1.PayGroup, "WorkPlace Monthly").Is(cell => cell.PayrollStatusLink, "innerHtml", "Not Started");
        }

        /// <summary>
        /// Verify that with W2 Approval records, where the system date is greater than the Final Reconciliation Date, there is a link in payroll status for Not Started.
        /// </summary>
        [Test]
        public void WithW2ApprovalsPayrollStatusNotStartedLinkPresent()
        {
            // Given there exists records in PAW2ApprovalDates and PAW2Approvals.
            this.database.Company.Execute("INSERT INTO PAW2ApprovalDates (paaFinalApprovalDate, paaFinalReconApprovalDate, paaYear) VALUES (DateAdd(dd, 1, getdate()), NULL, '2008')");
            this.database.Company.Execute("INSERT INTO PAW2ApprovalDates (paaFinalApprovalDate, paaFinalReconApprovalDate, paaYear) VALUES ('01/06/2008', NULL, '2007')");

            this.database.Company.Execute("INSERT INTO PAW2Approvals (pawAddressLine1, pawAddressLine2, pawApproved, pawApprovedBy, pawAttentionTo, pawChangedBy, pawChangedName, pawCity, pawDateTimeApproved, pawDateTimeChanged, pawDateTimePrinted, pawDateTimeReconApproved, pawDateTimeReconciled, pawPrintApprovedName, pawReconApprovedBy, pawReconApprovedName, pawReconciledBy, pawSortOrder, pawState, pawTaxGroup, pawYear, pawZipCode) values (null, null, 1, null, null, null, null, null, null, null, '01/16/2008', '01/02/2008', '01/14/2010', null, null, null, null, null, null, 'WKPL3', '2007', null)");
            this.database.Company.Execute("INSERT INTO PAW2Approvals (pawAddressLine1, pawAddressLine2, pawApproved, pawApprovedBy, pawAttentionTo, pawChangedBy, pawChangedName, pawCity, pawDateTimeApproved, pawDateTimeChanged, pawDateTimePrinted, pawDateTimeReconApproved, pawDateTimeReconciled, pawPrintApprovedName, pawReconApprovedBy, pawReconApprovedName, pawReconciledBy, pawSortOrder, pawState, pawTaxGroup, pawYear, pawZipCode) values (null, null, 1, null, null, null, null, null, null, null, '01/17/2008', '01/03/2008', '01/15/2010', null, null, null, null, null, null, 'WKPL4', '2007', null)");
            this.database.Company.Execute("INSERT INTO PAW2Approvals (pawAddressLine1, pawAddressLine2, pawApproved, pawApprovedBy, pawAttentionTo, pawChangedBy, pawChangedName, pawCity, pawDateTimeApproved, pawDateTimeChanged, pawDateTimePrinted, pawDateTimeReconApproved, pawDateTimeReconciled, pawPrintApprovedName, pawReconApprovedBy, pawReconApprovedName, pawReconciledBy, pawSortOrder, pawState, pawTaxGroup, pawYear, pawZipCode) values (null, null, 1, null, null, null, null, null, null, null, '01/18/2008', '01/04/2008', '01/16/2010', null, null, null, null, null, null, 'WP5', '2007', null)");
            this.database.Company.Execute("INSERT INTO PAW2Approvals (pawAddressLine1, pawAddressLine2, pawApproved, pawApprovedBy, pawAttentionTo, pawChangedBy, pawChangedName, pawCity, pawDateTimeApproved, pawDateTimeChanged, pawDateTimePrinted, pawDateTimeReconApproved, pawDateTimeReconciled, pawPrintApprovedName, pawReconApprovedBy, pawReconApprovedName, pawReconciledBy, pawSortOrder, pawState, pawTaxGroup, pawYear, pawZipCode) values (null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 'WKPL3', '2008', null)");
            this.database.Company.Execute("INSERT INTO PAW2Approvals (pawAddressLine1, pawAddressLine2, pawApproved, pawApprovedBy, pawAttentionTo, pawChangedBy, pawChangedName, pawCity, pawDateTimeApproved, pawDateTimeChanged, pawDateTimePrinted, pawDateTimeReconApproved, pawDateTimeReconciled, pawPrintApprovedName, pawReconApprovedBy, pawReconApprovedName, pawReconciledBy, pawSortOrder, pawState, pawTaxGroup, pawYear, pawZipCode) values (null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 'WKPL4', '2008', null)");
            this.database.Company.Execute("INSERT INTO PAW2Approvals (pawAddressLine1, pawAddressLine2, pawApproved, pawApprovedBy, pawAttentionTo, pawChangedBy, pawChangedName, pawCity, pawDateTimeApproved, pawDateTimeChanged, pawDateTimePrinted, pawDateTimeReconApproved, pawDateTimeReconciled, pawPrintApprovedName, pawReconApprovedBy, pawReconApprovedName, pawReconciledBy, pawSortOrder, pawState, pawTaxGroup, pawYear, pawZipCode) values (null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, 'WP5', '2008', null)");

            // When I visit Create Instant Checks.
            ultiPro.Macros.Payroll.GoToInstantChecks();
            ultiPro.Pages.WPREmployeePaySummary.WPREmployeePaySummaryGrid.Click(b => b.FilterButton);

            // Then Payroll status is not started with a link.
            this.ultiPro.Pages.WPREmployeePaySummary.WPREmployeePaySummaryGrid.Row(
                c => c.Name, "Appleton, Larry A.", c1 => c1.PayGroup, "WorkPlace Weekly").Is(cell => cell.PayrollStatusLink, "innerHtml", "Not Started");

            this.ultiPro.Pages.WPREmployeePaySummary.WPREmployeePaySummaryGrid.Row(
                c => c.Name, "Appleton, Larry A.", c1 => c1.PayGroup, "WorkPlace Monthly").Is(cell => cell.PayrollStatusLink, "innerHtml", "Not Started");
        }

        [Test]
        [Ignore("Per Elizabeth on 7/10/13 this test is invalid with the newer logic around the W2 Approvals.")]
        public void NoLinkExistsWhenSystemDataLessThanFinalReconcilliationDate()
        {
            /*
             * TC_W2AppYEUpdates_097.003
             * Verify that with W2 Approval records, where the system date is less than the Final Reconciliation Date, there is no 
             * link in payroll status for Not Started, and instead the status is Year End Reconciliation
             * */
        }
    }
}
